package com.llb666.shop.user.infrastructure.persistence.center;


import com.llb666.shop.user.domain.entity.Users;
import com.llb666.shop.user.domain.repository.center.CenterUserRepository;
import com.llb666.shop.user.infrastructure.conver.UsersCvt;
import com.llb666.shop.user.infrastructure.mapper.UsersMapper;
import com.llb666.shop.user.infrastructure.po.UsersPo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Date;

/**
 * 用户中心仓储层实现类.
 *
 * @author llb666
 */
@Repository
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class CenterUserRepositoryImpl implements CenterUserRepository {

    private final UsersMapper usersMapper;

    @Override
    public Users queryUserInfo(String userId) {
        Users users = UsersCvt.INSTANCE.po2do(usersMapper.selectByPrimaryKey(userId));
        users.setPassword(null);
        return users;
    }

    @Override
    public void updateUserFace(String userId, String faceUrl) {
        UsersPo updateUser = new UsersPo();
        updateUser.setId(userId);
        updateUser.setFace(faceUrl);
        updateUser.setUpdatedTime(new Date());
        usersMapper.updateByPrimaryKeySelective(updateUser);
    }

    @Override
    public void updateUserInfo(String userId, Users users) {
        users.setId(userId);
        users.setUpdatedTime(new Date());
        usersMapper.updateByPrimaryKeySelective(UsersCvt.INSTANCE.do2po(users));
    }
}
